<template>
  <div class="app-container">
    <!-- 添加或修改扩展插件对话框 -->
    <el-dialog :title="title" v-model="open" width="800px" v-if="open" append-to-body>
      <el-form ref="HotPlugApproveRef" :model="form" :rules="rules" label-width="110px" :disabled="disabled">
        <el-row>
          <el-col :span="12">
            <el-form-item label="插件名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入插件名称" maxlength="100" show-word-limit/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="作者" prop="author">
              <el-input v-model="form.author" placeholder="请输入作者" maxlength="100" show-word-limit/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="官方文档" prop="website">
              <el-input v-model="form.website" placeholder="请输入官方文档" maxlength="255" show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="插件包名" prop="jarName">
              <el-input v-model="form.jarName" placeholder="请输入插件包名" maxlength="255" show-word-limit/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-form-item label="审批意见" prop="message">
            <el-input v-model="form.message" type="textarea" placeholder="请输入审批意见"
                      :autosize="{minRows: 4, maxRows: 4}"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleBtn('PASS')">审批通过</el-button>
          <el-button @click="handleBtn('REJECT')">驳回</el-button>
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Approve">
import { getHotPlug, handle } from "@/api/system/hotPlug";
const { proxy } = getCurrentInstance();

const props = defineProps({
    /* 业务id */
    modelValue: {
        type: String,
        default: "",
    },

    /* 实例id */
    taskId: {
        type: String,
        default: "",
    },

    /* 是否可以标编辑 */
    disabled: {
        type: Boolean,
        default: false,
    },
})
// 是否显示弹出层
const open = ref(false);
// 弹出层标题
const title = ref("");

const data = reactive({
  form: {},
  rules: {
  }
});

const { form, rules } = toRefs(data);
const emit = defineEmits(["refresh"]);

function getInfo() {
  reset();
  getHotPlug(props.modelValue).then(response => {
      if (!response.data) {
          proxy.$modal.alertWarning("代办任务不存在");
      }
      form.value = response.data;
  });
  title.value = "办理"
  open.value = true
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    message: null,
    qualifiedName: null,
    author: null,
    website: null,
    jarName: null,
    tenantId: null,
    status: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("HotPlugApproveRef");
}

/** 审核通过按钮 */
function handleBtn(skipType) {
  proxy.$refs["HotPlugApproveRef"].validate(valid => {
    if (valid) {
      handle(form.value, props.taskId, skipType, form.value.message).then(() => {
        proxy.$modal.msgSuccess("办理成功");
        open.value = false;
        emit('refresh');
      });
    }
    });
}


getInfo();
</script>
